package com.sgcc.nfc.lock.data.remote.dto.map

import com.google.gson.annotations.SerializedName
import com.sgcc.nfc.lock.domain.model.MapPoint
import com.sgcc.nfc.lock.domain.model.RoomStatus

data class MapRoomDto(
    @SerializedName("roomId") val roomId: Long?,
    @SerializedName("roomName") val roomName: String?,
    @SerializedName("longitude") val longitude: Double?,
    @SerializedName("latitude") val latitude: Double?,
    @SerializedName("status") val status: Int?,
    @SerializedName("address") val address: String?,
    @SerializedName("lockCount") val lockCount: Int?,
    @SerializedName("openCount") val openCount: Int?,
    @SerializedName("malfunctionCount") val malfunctionCount: Int?
) {
    fun toDomain(): MapPoint? {
        val lng = longitude ?: return null
        val lat = latitude ?: return null
        return MapPoint(
            roomId = roomId ?: 0L,
            roomName = roomName.orEmpty(),
            longitude = lng,
            latitude = lat,
            status = when (status) {
                0 -> RoomStatus.NORMAL
                1 -> RoomStatus.IN_USE
                2 -> RoomStatus.ALERT
                else -> RoomStatus.UNKNOWN
            },
            address = address,
            lockCount = lockCount ?: 0,
            openCount = openCount ?: 0,
            malfunctionCount = malfunctionCount ?: 0
        )
    }
}
